package com.util;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by yangliwei on 2017/7/23.
 */
public class DateDemo {
    @Test
    public void testDate(){
        Date date = new Date();
        System.out.println(date);
    }

    /**
     * 获取时间精度 毫秒
     */
    @Test
    public void testDate1(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss:SSS ");
        System.out.println(sdf.format(new Date()));
    }



    /*
    将unix 时间戳 补齐到 13位，然后转化
     */
    @Test
    public void test001(){

        Long sendTime = 1569725518723024L;
        Long duration = 277620L;
//        Long timestamp = Long.parseLong("1437827940000");
//        Long timestamp = Long.parseLong("1569725356183415");
        Long timestamp = sendTime + duration;
        timestamp /=1000;
        String date = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS").format(new java.util.Date(timestamp));
        System.out.println(date);

    }


    @Test
    public void testSdf() throws ParseException {
        String start = "2020-2-15 00:00:00";
        String start1 = "2020-02-15 00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = sdf.parse(start);
        Date startDate1 = sdf.parse(start1);
        System.out.println(startDate);
        System.out.println(startDate1);
        System.out.println("------------");

    }

    @Test
    public void test01(){
        String yyyymMddHHmmssSSS = LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYYMMddHHmmssSSS"));
        System.out.println(yyyymMddHHmmssSSS);
    }
}
